package znbkTestPaperSc.presenter;

import android.util.Log;

import com.example.lancooznbk.view.base.ILoadPaperView;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import java.util.List;

import znbkListSc.ICollectionPresenter;
import znbkListSc.entity.CollectionListEntity;
import znbkTestPaperSc.ZnbkPaperScInfor;
import znbkTestPaperSc.activity.CollectionPaperActivity;
import znbkTestPaperSc.activity.CollectionPaperSplActivity;
import znbkTestPaperSc.api.CollectionPaperApi;
import znbkTestPaperSc.entity.CollectionPaperEntity;

/**
 * Created by Administrator on 2018\3\20 0020.
 */

public class CollectionPaperPresenter implements ICollectionPresenter {

    private ILoadPaperView view;

    public CollectionPaperPresenter(ILoadPaperView view) {
        this.view = (ILoadPaperView) view;
    }

    @Override
    public void getData(boolean isShowLoading) {
        if (isShowLoading) view.showLoading();

        HttpOnNextListener<CollectionPaperEntity> httpOnNextListener = new HttpOnNextListener<CollectionPaperEntity>() {
            @Override
            public void onNext(CollectionPaperEntity collectionPaperEntity) {


                if (collectionPaperEntity.getResDetail() != null) {
                    view.hideLoading();
                    view.loadPaperData(collectionPaperEntity);
                }else {
                    view.showNoData("暂无内容");
                }
            }


            @Override
            public void onError(Throwable e) {
                super.onError(e);
                view.showNetError();
            }

            @Override
            public void onComplete() {
                super.onComplete();
                Log.d("TML","end: "+System.currentTimeMillis());
            }
        };

        CollectionPaperApi api = null;
        if( ZnbkPaperScInfor.IsFromSpl){
            //来自视频类的解析
             api = new CollectionPaperApi(httpOnNextListener, (CollectionPaperSplActivity)view);
        }else {
            //来自非视频类的解析
             api = new CollectionPaperApi(httpOnNextListener, (CollectionPaperActivity) view);
        }

        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }


    @Override
    public void searchFavouriteItem(String str) {

    }

    @Override
    public void openFavoriteItemDetail(int position, CollectionListEntity.FavouriteBean favouriteBean) {

    }

    @Override
    public void delItemFavourite(int position, CollectionListEntity.FavouriteBean favouriteBean) {

    }
}